{include file='public/head'}
<body>
<style type="text/css" media="screen">
header {
    color: black;
}
</style>
<div class="x-body" style="width: 600px">
	<form class="layui-form" id='mainForm' method="post" action="add">
		<div class="layui-form-item">
			<label class="layui-form-label">类型</label>
			<div class="layui-input-block">
				<input type="radio" name="type" value="4" title="底部模块">
				<input type="radio" name="type" value="5" title="顶部轮播图">

			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">名称</label>
			<div class="layui-input-block">
				<input type="text" id="title"  name="title" lay-verify="required" autocomplete="off" placeholder="请输入模块名称" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">图片</label>
			<div class="layui-input-block">
				<input type="text" name="image" id="image"  lay-verify="required" style="display: none">
				<div class="layui-upload-list">
					<img id="demo1" src="/static/images/photo_icon.png" class="layui-upload-img" style="height: 120px;cursor:pointer;" title="点击添加图片">
					<p id="demoText1"></p>
				</div>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">链接</label>
			<div class="layui-input-block">
				<input type="text" id="link"  name="link" autocomplete="off" placeholder="请输入链接，可不填" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">权重</label>
			<div class="layui-input-block">
				<input type="number" id="rank"  name="rank" lay-verify="required" autocomplete="off" placeholder="序号小的排在前面" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
		    <div class="layui-input-block">
		      <button style="margin-left: 20%" class="layui-btn" lay-submit="" lay-filter="toSubmit">提交</button>
		      <button id="reset" type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</div>


	</form>
</div>
</body>
{include file='public/foot'}
<script type="text/javascript">
	layui.use(['upload','form'], function() {
		var  upload = layui.upload,form = layui.form;

		//普通图片上传
		var uploadInst1 = upload.render({
			elem: '#demo1'
			, url: '/admin/common/upFile'
			, before: function (obj) {
				//预读本地文件示例，不支持ie8
				obj.preview(function (index, file, result) {
					$('#demo1').attr('src', result); //图片链接（base64）
				});
			}
			, done: function (res) {
				//如果上传失败
				if (res.code == 0) {
					return layer.msg('上传失败');
				}
				//上传成功
				$('#image').val(res.data);
			}
			, error: function () {
				//演示失败状态，并实现重传
				var demoText = $('#demoText1');
				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
				demoText.find('.demo-reload').on('click', function () {
					uploadInst1.upload();
				});
			}
		});

	});
	$(document).ready(function(){ 
	     var options = {
		      type:'post',           //post提交
		      //url:'http://ask.tongzhuo100.com/server/****.php?='+Math.random(),   //url
		      dataType:"json",        //json格式
		      data:{},    //如果需要提交附加参数，视情况添加
		      clearForm: false,        //成功提交后，清除所有表单元素的值
		      resetForm: false,        //成功提交后，重置所有表单元素的值
		      cache:false,          
		      async:false,          //同步返回
		      success:function(data){
		      	console.log(data);
		      	if(data.code==0){
		      		layer.msg(data.msg);
		      	}else{
		      		layer.msg(data.msg,{icon:1,time:500},function(){
		      			$("#reset").click();
		      			x_admin_close();
		      			parent.location.reload();
		      		});
		      	}
		      //服务器端返回处理逻辑
		      	},
		      	error:function(XmlHttpRequest,textStatus,errorThrown){
		        	layer.msg('操作失败:服务器处理失败');
		      }
		    }; 
	    // bind form using 'ajaxForm' 
	    $('#mainForm').ajaxForm(options).submit(function(data){
	    	//无逻辑
	    }); 

	});
</script>
